<%@page import="edu.sjsu.itack.entity.Board"%>
<%@page import="edu.sjsu.itack.entity.User"%>
<%@page import="edu.sjsu.itack.dao.BoardDao"%>
<%@ page language="java" contentType="text/html; charset=US-ASCII"
	pageEncoding="US-ASCII"%>
<%@include file="header.jsp" %>

<aside class="aside">
	<ul class="nav nav-pills nav-stacked" id="myTab">
		<li class="dropdown"><a class="dropdown-toggle"
			data-toggle="dropdown" href="#">Settings<b class="caret"></b></a>
			<ul class="dropdown-menu">
				<li><a href="#profile" data-toggle="tab">Edit Profile</a></li>
				<li><a href="inviteFriends.jsp">Invite Friends</a></li>
			</ul></li>
		<li class="dropdown"><a class="dropdown-toggle"
			data-toggle="dropdown" href="#">Tacks<b class="caret"></b></a>
			<ul class="dropdown-menu">
				<li><a href="uploadWeb.jsp">Tack from Website</a></li>
				<li><a href="uploadTack.jsp">Upload tack</a></li>
			</ul></li>
		<li class="active"><a class="dropdown-toggle" href="board.jsp">Boards</a></li>
	</ul>
</aside>
<section class="section" id="section">
	<%@include file="new_board.jsp" %>
	<div class="nbtn">
		<button type="button" data-toggle="modal" data-target="#newBoard" class="btn btn-default">Create Board</button>
	</div>
	<%
		BoardDao boardDao = new BoardDao();
		User user = (User) session.getAttribute("user");
		Board[] boards = boardDao.getAllBoardsForUser(user.getUserId());

		for (Board board : boards) {
			String clazz = board.getType();
			String boardName = board.getName();
			String boardDescription = board.getDescription();
	%>


	<div class="board <%=clazz%>">
		<h3><a style="text-decoration: none;" href="view-tack.jsp?boardId=<%=board.getBoardId()%>"><%=boardName %></a></h3>
		<h6><%=boardDescription%></h6>
		<button class="btn btn-default"
			onclick='editBoard("<%=board.getBoardId()%>","<%=boardName%>","<%=boardDescription%>","<%=clazz%>")'>
			<span class="glyphicon glyphicon-pencil"></span></button>
	</div>
	<%}
 %>

	<script>
    function editBoard(id,name,desc,type){
    	document.getElementsByName("boardId")[0].value=id;
    	document.getElementsByName("ename")[0].value=name;
    	document.getElementsByName("edescription")[0].value=desc;
    	var typeList = document.getElementsByName("etype");
    	
    	if (typeList[0].value == type)
    		typeList[0].checked = "checked";
    	else typeList[1].checked = "checked";
    	
    	$('#editBoard').modal({show: true});
    }
 </script>
	<%@include file="edit_board.jsp"%>
</section>
